#!/usr/bin/python

import datetime

from google.appengine.api import users
from google.appengine.ext import db

from hips import datastore


def CreateInstitution():
  institution = datastore.Institution(name="test")
  return institution


def CreateDoctor():
  institution = CreateInstitution()
  institution.put()
  model = datastore.Doctor(
      institution=institution.key(),
      login=users.User(email="testuser@gmail.com"),
      name="Test Doctor MD",
      min_shifts=12,
      max_shifts=15,
      max_night_shifts=5,
      max_consecutive_days=5,
      active=True)
  return model


def CreateSchedule():
  institution = CreateInstitution()
  institution.put()
  model = datastore.Schedule(
      institution=institution.key(),
      start_time=datetime.datetime(2009, 6, 1))
  return model


def CreateDoctorConstraint(
    schedule=None,
    doctor=None,
    days_off=[1,2,3,4],
    min_shifts=9,
    max_shifts=10,
    max_night_shifts=4,
    max_consecutive_days=5):
  if not schedule:
    schedule = CreateSchedule()
    schedule.put()
  if not doctor:
    doctor = CreateDoctor()
    doctor.put()
  model = datastore.DoctorConstraint(
      doctor=doctor,
      schedule=schedule,
      days_off=days_off,
      min_shifts=min_shifts,
      max_shifts=max_shifts,
      max_night_shifts=max_night_shifts,
      max_consecutive_days=max_consecutive_days)
  return model


def CreateScheduleBlock(
    schedule=None,
    start_time=datetime.datetime(2009, 6, 1, 6),
    duration_minutes=12 * 60):
  if not schedule:
    schedule = CreateSchedule()
    schedule.put()
  model = datastore.ScheduleBlock(
      schedule=schedule,
      start_time=start_time,
      duration_minutes=duration_minutes)
  return model


def CreateScheduleSolution(
    schedule=None,
    message="This is a test message. Do you get it?"):
  if not schedule:
    schedule = CreateSchedule()
    schedule.put()
  model = datastore.ScheduleSolution(
      schedule=schedule,
      message=message)
  return model


def CreateScheduleSolutionBlock():
  solution = CreateScheduleSolution()
  solution.put()
  block = CreateScheduleBlock()
  block.put()
  doctor = CreateDoctor()
  doctor.put()
  model = datastore.ScheduleSolutionBlock(
      solution=solution,
      block=block,
      doctor=doctor)
  return model
